cssection: Return locations, not numbers
authorBenjamin Otte <otte@redhat.com>
Wed, 10 Apr 2019 03:18:14 +0000 (05:18 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 12 Apr 2019 17:34:28 +0000 (19:34 +0200)
Now that we have GtkCssLocation, actually use it.

demos/gtk-demo/css_basics.c
demos/gtk-demo/css_multiplebgs.c
demos/gtk-demo/css_pixbufs.c
demos/gtk-demo/css_shadows.c
docs/reference/gtk/gtk4-sections.txt
gtk/gtkcsssection.c
gtk/gtkcsssection.h
gtk/inspector/css-editor.c
tests/testboxcss.c
testsuite/css/parser/test-css-parser.c

index 258aacb46bd1d757ef0014a78a1baf1dc1ce3212..06b36483edd6a8996cdc08478641b0eeb85769d7 100644 (file)
@@ -13,17 +13,20 @@ show_parsing_error (GtkCssProvider *provider,
                     const GError   *error,
                     GtkTextBuffer  *buffer)
 {
+  const GtkCssLocation *start_location, *end_location;
   GtkTextIter start, end;
   const char *tag_name;
 
+  start_location = gtk_css_section_get_start_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &start,
-                                          gtk_css_section_get_start_line (section),
-                                          gtk_css_section_get_start_position (section));
+                                          start_location->lines,
+                                          start_location->line_bytes);
+  end_location = gtk_css_section_get_end_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &end,
-                                          gtk_css_section_get_end_line (section),
-                                          gtk_css_section_get_end_position (section));
+                                          end_location->lines,
+                                          end_location->line_bytes);
 
   if (error->domain == GTK_CSS_PARSER_WARNING)
     tag_name = "warning";
index e865521bbac08c709dbdaaec0188fb47a965d0f0..6475c2c31a84875d0e5e6995c89c6e14ceaceeb8 100644 (file)
@@ -13,17 +13,21 @@ show_parsing_error (GtkCssProvider *provider,
                     const GError   *error,
                     GtkTextBuffer  *buffer)
 {
+  const GtkCssLocation *start_location, *end_location;
   GtkTextIter start, end;
   const char *tag_name;
 
+  start_location = gtk_css_section_get_start_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &start,
-                                          gtk_css_section_get_start_line (section),
-                                          gtk_css_section_get_start_position (section));
+                                          start_location->lines,
+                                          start_location->line_bytes);
+  end_location = gtk_css_section_get_end_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &end,
-                                          gtk_css_section_get_end_line (section),
-                                          gtk_css_section_get_end_position (section));
+                                          end_location->lines,
+                                          end_location->line_bytes);
+
 
   if (error->domain == GTK_CSS_PARSER_WARNING)
     tag_name = "warning";
index 7cd5b975bb8db2be403c54fb0294a5f9e61d0450..4846102ac39568f6b44acd6a99238cde06a12ca6 100644 (file)
@@ -12,17 +12,21 @@ show_parsing_error (GtkCssProvider *provider,
                     const GError   *error,
                     GtkTextBuffer  *buffer)
 {
+  const GtkCssLocation *start_location, *end_location;
   GtkTextIter start, end;
   const char *tag_name;
 
+  start_location = gtk_css_section_get_start_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &start,
-                                          gtk_css_section_get_start_line (section),
-                                          gtk_css_section_get_start_position (section));
+                                          start_location->lines,
+                                          start_location->line_bytes);
+  end_location = gtk_css_section_get_end_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &end,
-                                          gtk_css_section_get_end_line (section),
-                                          gtk_css_section_get_end_position (section));
+                                          end_location->lines,
+                                          end_location->line_bytes);
+
 
   if (error->domain == GTK_CSS_PARSER_WARNING)
     tag_name = "warning";
index 318f12d632c60d8abf526e4f4f13fcce70398443..318141c896ccabd0aef6446a2359d23f6b6218a3 100644 (file)
@@ -11,17 +11,20 @@ show_parsing_error (GtkCssProvider *provider,
                     const GError   *error,
                     GtkTextBuffer  *buffer)
 {
+  const GtkCssLocation *start_location, *end_location;
   GtkTextIter start, end;
   const char *tag_name;
 
+  start_location = gtk_css_section_get_start_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &start,
-                                          gtk_css_section_get_start_line (section),
-                                          gtk_css_section_get_start_position (section));
+                                          start_location->lines,
+                                          start_location->line_bytes);
+  end_location = gtk_css_section_get_end_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &end,
-                                          gtk_css_section_get_end_line (section),
-                                          gtk_css_section_get_end_position (section));
+                                          end_location->lines,
+                                          end_location->line_bytes);
 
   if (error->domain == GTK_CSS_PARSER_WARNING)
     tag_name = "warning";
index 3b26ffe436f678152ce46bbdd7cfd40605ea4d93..bf980695426fd8a0c990f6f09d102b599326256f 100644 (file)
@@ -5092,12 +5092,10 @@ GtkCssParserWarning
 <SUBSECTION>
 GtkCssLocation
 GtkCssSection
-gtk_css_section_get_end_line
-gtk_css_section_get_end_position
 gtk_css_section_get_file
 gtk_css_section_get_parent
-gtk_css_section_get_start_line
-gtk_css_section_get_start_position
+gtk_css_section_get_start_location
+gtk_css_section_get_end_location
 gtk_css_section_ref
 gtk_css_section_unref
 <SUBSECTION Standard>
index c514f276511a507862409efee69b09a80520f213..6fae99d6bfbbebfc8ac2f36c6ee4d71eb98fdf77 100644 (file)
@@ -150,97 +150,40 @@ gtk_css_section_get_file (const GtkCssSection *section)
 }
 
 /**
- * gtk_css_section_get_start_line:
+ * gtk_css_section_get_start_location:
  * @section: the section
  *
- * Returns the line in the CSS document where this section starts.
- * The line number is 0-indexed, so the first line of the document
- * will return 0.
+ * Returns the location in the CSS document where this section starts.
  *
- * Returns: the line number
+ * Returns: (tranfer none) (not nullable): The start location of
+ *     this section
  **/
-guint
-gtk_css_section_get_start_line (const GtkCssSection *section)
+const GtkCssLocation *
+gtk_css_section_get_start_location (const GtkCssSection *section)
 {
-  gtk_internal_return_val_if_fail (section != NULL, 0);
-
-  return section->start_location.lines;
-}
-
-/**
- * gtk_css_section_get_start_position:
- * @section: the section
- *
- * Returns the offset in bytes from the start of the current line
- * returned via gtk_css_section_get_start_line().
- *
- * Returns: the offset in bytes from the start of the line.
- **/
-guint
-gtk_css_section_get_start_position (const GtkCssSection *section)
-{
-  gtk_internal_return_val_if_fail (section != NULL, 0);
-
-  return section->start_location.line_chars;
-}
-
-/**
- * gtk_css_section_get_end_line:
- * @section: the section
- *
- * Returns the line in the CSS document where this section end.
- * The line number is 0-indexed, so the first line of the document
- * will return 0.
- * This value may change in future invocations of this function if
- * @section is not yet parsed completely. This will for example 
- * happen in the GtkCssProvider::parsing-error signal.
- * The end position and line may be identical to the start
- * position and line for sections which failed to parse anything
- * successfully.
- *
- * Returns: the line number
- **/
-guint
-gtk_css_section_get_end_line (const GtkCssSection *section)
-{
-  GtkCssLocation location;
-
-  gtk_internal_return_val_if_fail (section != NULL, 0);
-
-  if (!section->parser)
-    return section->end_location.lines;
+  gtk_internal_return_val_if_fail (section != NULL, NULL);
 
-  gtk_css_parser_get_location (section->parser, &location);
-  return location.lines;
+  return &section->start_location;
 }
 
 /**
- * gtk_css_section_get_end_position:
+ * gtk_css_section_get_end_location:
  * @section: the section
  *
- * Returns the offset in bytes from the start of the current line
- * returned via gtk_css_section_get_end_line().
- * This value may change in future invocations of this function if
- * @section is not yet parsed completely. This will for example
- * happen in the GtkCssProvider::parsing-error signal.
- * The end position and line may be identical to the start
- * position and line for sections which failed to parse anything
- * successfully.
+ * Returns the location in the CSS document where this section ends.
  *
- * Returns: the offset in bytes from the start of the line.
+ * Returns: (tranfer none) (not nullable): The end location of
+ *     this section
  **/
-guint
-gtk_css_section_get_end_position (const GtkCssSection *section)
+const GtkCssLocation *
+gtk_css_section_get_end_location (const GtkCssSection *section)
 {
-  GtkCssLocation location;
-
-  gtk_internal_return_val_if_fail (section != NULL, 0);
+  gtk_internal_return_val_if_fail (section != NULL, NULL);
 
-  if (!section->parser)
-    return section->end_location.line_chars;
+  if (section->parser)
+    gtk_css_parser_get_location (section->parser, (GtkCssLocation *) &section->end_location);
 
-  gtk_css_parser_get_location (section->parser, &location);
-  return location.line_chars;
+  return &section->end_location;
 }
 
 void
@@ -268,9 +211,9 @@ _gtk_css_section_print (const GtkCssSection  *section,
       g_string_append (string, "<data>");
     }
 
-  g_string_append_printf (string, ":%u:%u", 
-                          gtk_css_section_get_end_line (section) + 1,
-                          gtk_css_section_get_end_position (section));
+  g_string_append_printf (string, ":%zu:%zu", 
+                          section->end_location.lines + 1,
+                          section->end_location.line_chars + 1);
 }
 
 char *
index 4927cd1cc0ff786a6e308c0f3605ffdbbd8cec6e..5763aad2042096529d30ecfdc8cb1f81355f6793 100644 (file)
@@ -19,7 +19,7 @@
 #define __GTK_CSS_SECTION_H__
 
 #include <gio/gio.h>
-#include <gdk/gdk.h>
+#include <gtk/css/gtkcss.h>
 
 G_BEGIN_DECLS
 
@@ -47,13 +47,11 @@ GtkCssSection *    gtk_css_section_get_parent          (const GtkCssSection  *se
 GDK_AVAILABLE_IN_ALL
 GFile *            gtk_css_section_get_file            (const GtkCssSection  *section);
 GDK_AVAILABLE_IN_ALL
-guint              gtk_css_section_get_start_line      (const GtkCssSection  *section);
+const GtkCssLocation *
+                   gtk_css_section_get_start_location  (const GtkCssSection  *section);
 GDK_AVAILABLE_IN_ALL
-guint              gtk_css_section_get_start_position  (const GtkCssSection  *section);
-GDK_AVAILABLE_IN_ALL
-guint              gtk_css_section_get_end_line        (const GtkCssSection  *section);
-GDK_AVAILABLE_IN_ALL
-guint              gtk_css_section_get_end_position    (const GtkCssSection  *section);
+const GtkCssLocation *
+                   gtk_css_section_get_end_location    (const GtkCssSection  *section);
 
 G_END_DECLS
 
index 7033bbd047ec5632c7f4abd58ed9efc831bce953..4f253d91caeb33d5b731a8db36a72dea2b56695d 100644 (file)
@@ -292,19 +292,22 @@ show_parsing_error (GtkCssProvider        *provider,
 {
   const char *tag_name;
   GtkTextBuffer *buffer = GTK_TEXT_BUFFER (ce->priv->text);
+  const GtkCssLocation *start, *end;
   CssError *css_error;
 
   css_error = g_new (CssError, 1);
   css_error->error = g_error_copy (error);
 
+  start = gtk_css_section_get_start_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &css_error->start,
-                                          gtk_css_section_get_start_line (section),
-                                          gtk_css_section_get_start_position (section));
+                                          start->lines,
+                                          start->line_bytes);
+  end = gtk_css_section_get_end_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &css_error->end,
-                                          gtk_css_section_get_end_line (section),
-                                          gtk_css_section_get_end_position (section));
+                                          end->lines,
+                                          end->line_bytes);
 
   if (error->domain == GTK_CSS_PARSER_WARNING)
     tag_name = "warning";
index 7742f7551006f5b789be718c90be0d0cf5f79ff1..2a72309724b622f0745198c328a25402dcb9138b 100644 (file)
@@ -49,17 +49,20 @@ show_parsing_error (GtkCssProvider *provider,
                     const GError   *error,
                     GtkTextBuffer  *buffer)
 {
+  const GtkCssLocation *start_location, *end_location;
   GtkTextIter start, end;
   const char *tag_name;
 
+  start_location = gtk_css_section_get_start_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &start,
-                                          gtk_css_section_get_start_line (section),
-                                          gtk_css_section_get_start_position (section));
+                                          start_location->lines,
+                                          start_location->line_bytes);
+  end_location = gtk_css_section_get_end_location (section);
   gtk_text_buffer_get_iter_at_line_index (buffer,
                                           &end,
-                                          gtk_css_section_get_end_line (section),
-                                          gtk_css_section_get_end_position (section));
+                                          end_location->lines,
+                                          end_location->line_bytes);
 
   if (error->domain == GTK_CSS_PARSER_WARNING)
     tag_name = "warning";
index 4fa12810145509ee8c416453199bb31c47bf9153..6e9f3efc316b2f21f2e3926af5820ca7c85f1f3c 100644 (file)
@@ -142,12 +142,15 @@ parsing_error_cb (GtkCssProvider *provider,
                   const GError   *error,
                   GString        *errors)
 {
+  const GtkCssLocation *end_location;
   char *basename;
 
+  end_location = gtk_css_section_get_end_location (section);
+
   basename = g_file_get_basename (gtk_css_section_get_file (section));
   g_string_append_printf (errors,
-                          "%s:%u: error: ",
-                          basename, gtk_css_section_get_end_line (section) + 1);
+                          "%s:%zu: error: ",
+                          basename, end_location->lines + 1);
   g_free (basename);
 
   if (error->domain == GTK_CSS_PARSER_ERROR)